<template>
	<div>
		<form @submit.prevent="nextStep">
			<div class="carEditorSubmit">
				<button class="button button-icon" slot="right" type="submit" style="color: #fff; font-size: 13px;">确定</button>
				<input type="number" name="carId" v-model="routerParams.carId" style="display: none;" />
			</div>
			<div class="page has-navbar has-tabbar" v-nav="{title: '销售定价', showBackButton: true}">
				<div class="page-content padding-top reserve-margin">
					<div class="car-editor">

						<div class="reserve">
							<list>
								<!--<item>
									<div class="car-enitor-tr">
										<div class="car-editor-name">新车指导价</div>
										<div class="car-editor-input"><input type="number" step="0.01" name="carGuidePrice" v-model="routerParams.carGuidePrice" /></div>
										<div class="car-editor-right">万元</div>
									</div>
								</item>
								<item>
									<div class="car-enitor-tr">
										<div class="car-editor-name">销售底价</div>
										<div class="car-editor-input"><input type="number" step="0.01" name="carFloorPrice" v-model="routerParams.carFloorPrice" /></div>
										<div class="car-editor-right">万元</div>
									</div>
								</item>-->
								<item>
									<div class="car-enitor-tr">
										<div class="car-editor-name">是否面议</div>
										<div class="car-editor-input"></div>
										<div class="car-editor-right">
											<div class="item item-borderless item-toggle von-toggle">
												<label class="toggle toggle-balanced">
										            <input type="checkbox" v-model="carRetailPriceTrue">
										            <div class="track">
										            	<div class="handle"></div>
										            </div>
										        </label>
											</div>
										</div>
									</div>
								</item>
								<item v-if="!carRetailPriceTrue">
									<div class="car-enitor-tr active">
										<div class="car-editor-name">零售价</div>
										<div class="car-editor-input"><input type="number" required step="0.01" min="0.01" v-model="routerParams.carRetailPrice" placeholder="请输入零售价" /></div>
										<div class="car-editor-right">万元</div>
									</div>
								</item>
								<!--<item>
									<div class="car-enitor-tr">
										<div class="car-editor-name">完税价</div>
										<div class="car-editor-input"><input type="number" step="0.01" name="carTaxPrice" v-model="routerParams.carTaxPrice" /></div>
										<div class="car-editor-right">万元</div>
									</div>
								</item>
								<item>
									<div class="car-enitor-tr active">
										<div class="car-editor-name">展厅价</div>
										<div class="car-editor-input"><input type="number" required step="0.01" name="carShowPrice" v-model="routerParams.carShowPrice" /></div>
										<div class="car-editor-right">万元</div>
									</div>
								</item>
								<item>
									<div class="car-enitor-tr">
										<div class="car-editor-name">网络价</div>
										<div class="car-editor-input"><input type="number" step="0.01" name="carNetworkPrice" v-model="routerParams.carNetworkPrice" /></div>
										<div class="car-editor-right">万元</div>
									</div>
								</item>-->
								<item>
									<div class="car-enitor-tr">
										<div class="car-editor-name">包含过户费</div>
										<div class="car-editor-input"></div>
										<div class="car-editor-right">
											<div class="item item-borderless item-toggle von-toggle">
													<label class="toggle toggle-balanced">
											            <input type="checkbox" v-model="abc">
											            <div class="track">
											            	<div class="handle"></div>
											            </div>
											        </label>
												</div>
										</div>
										<input type="text" v-model="routerParams.carTransferState" name="carTransferState" class="none" />
									</div>
								</item>
								<item>
									<div class="car-enitor-tr">
										<div class="car-editor-name">是否一口价</div>
										<div class="car-editor-input"></div>
										<div class="car-editor-right">
											<div class="item item-borderless item-toggle von-toggle">
													<label class="toggle toggle-balanced">
											            <input type="checkbox" v-model="def">
											            <div class="track">
											            	<div class="handle"></div>
											            </div>
											        </label>
												</div>
										</div>
										<input type="text" v-model="routerParams.carFixedPriceState" name="carFixedPriceState" class="none" />
									</div>
								</item>
							</list>
						</div>

					</div>
				</div>
			</div>
		</form>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				abc: false,
				def: false,
				carRetailPriceTrue:false,
			}
		},
		methods: {
			nextStep(event) {
				$dialog.confirm({
					// 标题					
					title: '提示',
					content: '是否提交修改',
					// 取消按钮文本
					cancelText: '取消',
					// 确定按钮文本
					okText: '提交'
				}).then((res) => {
					if(res) {
						var formData = new FormData(event.target);
						this.carRetailPriceTrue?formData.append('carRetailPrice',0):formData.append('carRetailPrice',this.routerParams.carRetailPrice)
						window.axios.post(baseUrl + '/controller/car/updateCar', formData).then((data) => {
							if(data){
								setTimeout(()=>{
									$toast.show('修改成功', 2000)
									setTimeout(()=>{
										this.$router.go(-1)
									},2000)
								},400)
							}
						})
					}
				})
			},
			userIs(){
				if(!(this.userSession)) {
					$toast.show('请登录', 2000).then(() => {
						
					})
					setTimeout(()=>{
						this.$router.push({
							path: '/'
						})
					},1000)
					
				}
				if(!(this.$route.query.params.carId)) {
					$toast.show('获取失败', 2000).then(() => {
						
					})
					setTimeout(()=>{
						this.$router.go(-1)
					},1000)
				}
			}
		},
		computed: {
			routerParams() {
				return this.$route.query.params
			},
			userSession() {
				return sess.get('userSession')
			}
		},
		watch: {
			'abc': function() {
				if(this.abc) {
					this.routerParams.carTransferState = 1
				} else {
					this.routerParams.carTransferState = 0
				}
			},
			'def': function() {
				if(this.def) {
					this.routerParams.carFixedPriceState = 1
				} else {
					this.routerParams.carFixedPriceState = 0
				}
			},			
		},
		mounted() {
			this.abc = this.routerParams.carTransferState == 1 ? true : false
			this.def = this.routerParams.carFixedPriceState == 1 ? true : false
			this.userIs()
		}
	}
</script>